/*
 * Copyright 2020, Zetyun DEP All rights reserved.
 */

package ${package.Controller};

import ${cfg.dto}.${entity}Dto;
import com.zetyun.dep.common.core.web.controller.BaseController;
import com.zetyun.dep.common.core.web.domain.AjaxResult;
import ${package.Service}.${table.serviceName};
import ${package.Entity}.${table.entityName};
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * ${table.comment}
 * @author zhangjw
 * @since ${cfg.time}
 */
@RestController
@RequestMapping("/${cfg.entiName}")
public class ${table.controllerName} extends BaseController {
    @Autowired
    private ${table.serviceName} ${cfg.entiName}Service;

    /**
     * 列表.
     */
    @GetMapping("/list")
    public AjaxResult<Object> list(${entity}Dto ${cfg.entiName}) {
        startPage();
        List<${entity}> list = ${cfg.entiName}Service.selectList(${cfg.entiName});
        return getDataTable(list);
    }

    /**
     * 信息.
     */
    @GetMapping("/{${cfg.entiName}Id}")
    public AjaxResult<${entity}> getById(@PathVariable Integer ${cfg.entiName}Id) {
        ${entity} ${cfg.entiName} = ${cfg.entiName}Service.getById(${cfg.entiName}Id);
        return AjaxResult.success(${cfg.entiName});
    }

    /**
     * 保存.
     */
    @PostMapping
    public AjaxResult<Object> insert(@RequestBody ${entity}Dto ${cfg.entiName}) {
        return ${cfg.entiName}Service.insert(${cfg.entiName});
    }

    /**
     * 修改.
     */
    @PutMapping
    public AjaxResult<Object> update(@RequestBody ${entity}Dto ${cfg.entiName}Dto) {
        return toAjax(${cfg.entiName}Service.update(${cfg.entiName}Dto));
    }

    /**
     * 删除.
     */
    @DeleteMapping("/{${cfg.entiName}Id}")
    public AjaxResult<Object> deleteById(@PathVariable Integer ${cfg.entiName}Id) {
        ${cfg.entiName}Service.deleteById(${cfg.entiName}Id);
        return AjaxResult.success();
    }

    /**
     * 批量删除.
     */
    @DeleteMapping
    public AjaxResult<Object> deleteByIds(@RequestBody Integer[] ${cfg.entiName}Ids) {
        ${cfg.entiName}Service.deleteByIds(${cfg.entiName}Ids);
        return AjaxResult.success();
    }

}
